import Vue from 'vue'
// 直接将Vue组件作为Vue.extend的参数
import loadingBoxEvent from "./loading";


const getLoading = () => {
    const loadingBoxEventConstructor = Vue.extend(loadingBoxEvent);
    const instance = new loadingBoxEventConstructor({
        el: document.createElement("div")
    });

    document.querySelector("body").appendChild(instance.$el);
    return instance;
}

class Loading {
    constructor(loadingObj) {
        this.loadingObj = loadingObj;
    }

    static show(text) {
        if (this.loadingObj) {
            this.loadingObj.show(text)
        } else {
            this.loadingObj = getLoading();
            this.loadingObj.show(text)
        }
    }
    static hide() {
        if (this.loadingObj) {
            this.loadingObj.hide()
        }
    }
}

export default Loading;